package com.wxapp.market.service.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.wxapp.common.constant.base.IBaseController;
import com.wxapp.common.constant.pojo.vm.ResultVm;
import com.wxapp.common.constant.pojo.vo.UserVo;
import com.wxapp.common.core.annotation.User;
import com.wxapp.common.core.filter.except.ThrowMyException;
import com.wxapp.market.api.pojo.vm.adFile.PAdFileDetailVm;
import com.wxapp.market.api.pojo.vm.adFile.PAdFilePageVm;
import com.wxapp.market.api.pojo.vo.adFile.QAdFileAddVo;
import com.wxapp.market.api.pojo.vo.adFile.QAdFilePageVo;
import com.wxapp.market.api.pojo.vo.adFile.QAdFileUpdateVo;
import com.wxapp.market.service.service.AdFileService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@Tag(name = "推送广告文件管理")
@RequestMapping("ad/file")
@RequiredArgsConstructor
public class AdFileController extends IBaseController {
    private final AdFileService adFileService;

    @PostMapping("add")
    @Operation(summary = "添加推送广告文件")
    public ResultVm<String> add(@RequestBody @Validated QAdFileAddVo qAdFileAddVo, @Schema(hidden = true) @User UserVo userVo) {
        return adFileService.add(qAdFileAddVo, userVo);
    }

    @PutMapping("update")
    @Operation(summary = "更新推送广告文件")
    public ResultVm<String> update(@RequestBody @Validated QAdFileUpdateVo qAdFileUpdateVo, @Schema(hidden = true) @User UserVo userVo) throws ThrowMyException {
        return adFileService.update(qAdFileUpdateVo, userVo);
    }

    @PostMapping("page")
    @Operation(summary = "获取推送广告文件列表")
    public ResultVm<IPage<PAdFilePageVm>> getPage(@RequestBody QAdFilePageVo qAdFilePageVo) {
        return adFileService.getPage(qAdFilePageVo);
    }

    @DeleteMapping("delete/{id}")
    @Operation(summary = "删除推送广告文件")
    public ResultVm<String> delete(@PathVariable String id) throws ThrowMyException {
        return adFileService.delete(id);
    }

    @GetMapping("/detail/{id}")
    @Operation(summary = "获取推送广告文件详细信息")
    public ResultVm<PAdFileDetailVm> detail(@PathVariable String id) throws ThrowMyException {
        return adFileService.detail(id);
    }
}
